package com.kla.power.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.kla.power.config.LogPointer;
import com.kla.power.entity.InverterElectricEntity;
import com.kla.power.service.IInverterElectricService;
import com.kla.power.util.CommonUtil;
import com.kla.power.util.ResultBody;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 逆变器发电数据 前端控制器
 * </p>
 *
 * @author WuZH
 * @since 2024-06-02
 */
@RestController
@RequestMapping ( "/inverterElectric" )
@CrossOrigin ( value = "*", maxAge = 3600 )
public class InverterElectricController {


    @Resource
    private IInverterElectricService iInverterElectricService;

    @RequestMapping ( "querySingle" )
    public ResultBody querySingle ( @RequestBody InverterElectricEntity inverterElectricEntity ) {
        inverterElectricEntity = iInverterElectricService.querySingle ( inverterElectricEntity );
        return ResultBody.success ( inverterElectricEntity );
    }

    /**
     * 逆变器详情页总直流功率和总有功功率
     *
     * @param inverterElectricEntity {
     *                               createTime：查询某一天
     *                               }
     * @return
     */
    @RequestMapping ( "queryList" )
    @LogPointer ( "逆变器实时功率列表" )
    public ResultBody queryList ( @RequestBody InverterElectricEntity inverterElectricEntity ) {
        List<InverterElectricEntity> inverterElectricEntities = iInverterElectricService.getBaseMapper ().selectList ( new QueryWrapper<InverterElectricEntity> ().eq ( "serialNumber", inverterElectricEntity.getSerialNumber () ).eq ( "DATE_FORMAT (createTime,'%Y-%m-%d')", CommonUtil.getDateStrFormat ( inverterElectricEntity.getCreateTime (), "yyyy-MM-dd" ) ) );
        return ResultBody.success ( inverterElectricEntities );
    }


}
